package me.sdevil507.supports.shiro.helper;

import org.apache.shiro.SecurityUtils;

import java.util.Set;

/**
 * 账户帮助类
 *
 * @author sdevil507
 * created on 2020/2/27
 */
public class OrgAccountHelper {

    private static String orgIdStr = "orgId";

    private static String orgIdListStr = "orgIdList";

    private static String orgTypeStr = "orgType";

    private static String orgNameStr = "orgName";

    private static String userIdStr = "userId";

    private static String deptIdStr = "deptId";

    /**
     * 获取当前登录用户用户名
     *
     * @return 用户名
     */
    public static String getUsername() {
        return SecurityUtils.getSubject().getPrincipal().toString();
    }

    /**
     * 用户id
     *
     * @param userId 用户id
     */
    public static void setUserId(Long userId) {
        SecurityUtils.getSubject().getSession().setAttribute(OrgAccountHelper.userIdStr, userId);
    }

    public static Long getUserId() {
        return (Long) SecurityUtils.getSubject().getSession().getAttribute(OrgAccountHelper.userIdStr);
    }

    /**
     * 设置登录用户所属组织
     *
     * @param orgId 机构id
     */
    public static void setOrgId(Long orgId) {
        SecurityUtils.getSubject().getSession().setAttribute(OrgAccountHelper.orgIdStr, orgId);
    }

    /**
     * 设置登录用户所属组织
     *
     * @param orgIdList 机构idList
     */
    public static void setOrgIdList(Set<Long> orgIdList) {
        SecurityUtils.getSubject().getSession().setAttribute(OrgAccountHelper.orgIdListStr, orgIdList);
    }

    public static void setDeptId(Long deptId) {
        SecurityUtils.getSubject().getSession().setAttribute(OrgAccountHelper.deptIdStr, deptId);
    }

    /**
     * 获取当前用户所属组织
     *
     * @return orgId
     */
    public static Long getOrgId() {
        return (Long) SecurityUtils.getSubject().getSession().getAttribute(OrgAccountHelper.orgIdStr);
    }

    public static Set<Long> getOrgIdList() {
        return (Set<Long>) SecurityUtils.getSubject().getSession().getAttribute(OrgAccountHelper.orgIdListStr);
    }

    public static Long getDeptId() {
        return (Long) SecurityUtils.getSubject().getSession().getAttribute(OrgAccountHelper.deptIdStr);
    }

    public static String getOrgName() {
        return (String) SecurityUtils.getSubject().getSession().getAttribute(OrgAccountHelper.orgNameStr);
    }

    public static void setOrgName(String orgName) {
        SecurityUtils.getSubject().getSession().setAttribute(OrgAccountHelper.orgNameStr, orgName);
    }

    /**
     * 设置登录用户所属类型
     *
     */
    public static void setOrgType(String orgType) {
        SecurityUtils.getSubject().getSession().setAttribute(OrgAccountHelper.orgTypeStr, orgType);
    }

    /**
     * 获取当前用户所属类型
     *
     * @return orgId
     */
    public static String getOrgType() {
        return (String) SecurityUtils.getSubject().getSession().getAttribute(OrgAccountHelper.orgTypeStr);
    }
}
